/**
 * "Visual Paradigm: DO NOT MODIFY THIS FILE!"
 * 
 * This is an automatic generated file. It will be regenerated every time 
 * you generate persistence class.
 * 
 * Modifying its content may cause the program not work, or your work may lost.
 */

/**
 * Licensee: Carla Painemilla
 * License Type: Evaluation
 */
package orm.impl;

import org.orm.*;
import org.hibernate.Query;
import java.util.List;
import orm.*;

public class AnotacionDAOImpl implements orm.dao.AnotacionDAO {
	public Anotacion loadAnotacionByORMID(int anotacion_id) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return loadAnotacionByORMID(session, anotacion_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion getAnotacionByORMID(int anotacion_id) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return getAnotacionByORMID(session, anotacion_id);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion loadAnotacionByORMID(int anotacion_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return loadAnotacionByORMID(session, anotacion_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion getAnotacionByORMID(int anotacion_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return getAnotacionByORMID(session, anotacion_id, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion loadAnotacionByORMID(PersistentSession session, int anotacion_id) throws PersistentException {
		try {
			return (Anotacion) session.load(orm.Anotacion.class, new Integer(anotacion_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion getAnotacionByORMID(PersistentSession session, int anotacion_id) throws PersistentException {
		try {
			return (Anotacion) session.get(orm.Anotacion.class, new Integer(anotacion_id));
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion loadAnotacionByORMID(PersistentSession session, int anotacion_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Anotacion) session.load(orm.Anotacion.class, new Integer(anotacion_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion getAnotacionByORMID(PersistentSession session, int anotacion_id, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			return (Anotacion) session.get(orm.Anotacion.class, new Integer(anotacion_id), lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion[] listAnotacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return listAnotacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion[] listAnotacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return listAnotacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion[] listAnotacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Anotacion as Anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			List list = query.list();
			return (Anotacion[]) list.toArray(new Anotacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion[] listAnotacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Anotacion as Anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			List list = query.list();
			return (Anotacion[]) list.toArray(new Anotacion[list.size()]);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion loadAnotacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return loadAnotacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion loadAnotacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return loadAnotacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion loadAnotacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		Anotacion[] anotacions = listAnotacionByQuery(session, condition, orderBy);
		if (anotacions != null && anotacions.length > 0)
			return anotacions[0];
		else
			return null;
	}
	
	public Anotacion loadAnotacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		Anotacion[] anotacions = listAnotacionByQuery(session, condition, orderBy, lockMode);
		if (anotacions != null && anotacions.length > 0)
			return anotacions[0];
		else
			return null;
	}
	
	public static java.util.Iterator iterateAnotacionByQuery(String condition, String orderBy) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return iterateAnotacionByQuery(session, condition, orderBy);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateAnotacionByQuery(String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		try {
			PersistentSession session = orm.DiagnosticoPersistentManager.instance().getSession();
			return iterateAnotacionByQuery(session, condition, orderBy, lockMode);
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateAnotacionByQuery(PersistentSession session, String condition, String orderBy) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Anotacion as Anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public static java.util.Iterator iterateAnotacionByQuery(PersistentSession session, String condition, String orderBy, org.hibernate.LockMode lockMode) throws PersistentException {
		StringBuffer sb = new StringBuffer("From orm.Anotacion as Anotacion");
		if (condition != null)
			sb.append(" Where ").append(condition);
		if (orderBy != null)
			sb.append(" Order By ").append(orderBy);
		try {
			Query query = session.createQuery(sb.toString());
			query.setLockMode("this", lockMode);
			return query.iterate();
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public Anotacion createAnotacion() {
		return new orm.Anotacion();
	}
	
	public boolean save(orm.Anotacion anotacion) throws PersistentException {
		try {
			orm.DiagnosticoPersistentManager.instance().saveObject(anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean delete(orm.Anotacion anotacion) throws PersistentException {
		try {
			orm.DiagnosticoPersistentManager.instance().deleteObject(anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Anotacion anotacion)throws PersistentException {
		try {
			if(anotacion.getTipotianotacion() != null) {
				anotacion.getTipotianotacion().anotacion.remove(anotacion);
			}
			
			if(anotacion.getSubsectorsub() != null) {
				anotacion.getSubsectorsub().anotacion.remove(anotacion);
			}
			
			if(anotacion.getAnotadoranot() != null) {
				anotacion.getAnotadoranot().anotacion.remove(anotacion);
			}
			
			if(anotacion.getAlumnoalu() != null) {
				anotacion.getAlumnoalu().anotacion.remove(anotacion);
			}
			
			return delete(anotacion);
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean deleteAndDissociate(orm.Anotacion anotacion, org.orm.PersistentSession session)throws PersistentException {
		try {
			if(anotacion.getTipotianotacion() != null) {
				anotacion.getTipotianotacion().anotacion.remove(anotacion);
			}
			
			if(anotacion.getSubsectorsub() != null) {
				anotacion.getSubsectorsub().anotacion.remove(anotacion);
			}
			
			if(anotacion.getAnotadoranot() != null) {
				anotacion.getAnotadoranot().anotacion.remove(anotacion);
			}
			
			if(anotacion.getAlumnoalu() != null) {
				anotacion.getAlumnoalu().anotacion.remove(anotacion);
			}
			
			try {
				session.delete(anotacion);
				return true;
			} catch (Exception e) {
				return false;
			}
		}
		catch(Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean refresh(orm.Anotacion anotacion) throws PersistentException {
		try {
			orm.DiagnosticoPersistentManager.instance().getSession().refresh(anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
	public boolean evict(orm.Anotacion anotacion) throws PersistentException {
		try {
			orm.DiagnosticoPersistentManager.instance().getSession().evict(anotacion);
			return true;
		}
		catch (Exception e) {
			e.printStackTrace();
			throw new PersistentException(e);
		}
	}
	
}
